<template>
	<view id="content">

		<!-- 搜索部分 -->
		<view class="search_div">
			<view class="search_border">
				<input class="et_word" maxlength="24" placeholder="请输入关键字" :value="word" @input="onInputWord" />
				<view style="color: #ccc;">|</view>
				<view style="padding: 24rpx 36rpx 24rpx 24rpx;" @click.stop="onSearch">搜索</view>
			</view>
		</view>

		<view style="margin: 100rpx 0 0 0;">
			<view class="data_item" v-for="(item,index) in data_list" :key="item.id" @click.stop="onSelData(item)">
				<view>{{item.name || '暂未填写'}}</view>
				<view style="margin: 16rpx 0 0 0;color: #888;">{{item.subname}}</view>
				<view style="height: 1rpx;width: 100%;background-color: #ddd;margin: 16rpx 0 0 0;"></view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				data_list: [],
				word: '',
			}
		},

		mounted() {
			this.getDataList()
		},

		methods: {


			// 点击选择数据
			onSelData(item) {
				uni.$emit('onSelGoods', { msg: item })
				uni.navigateBack()
			},
			// 监听:输入关键字
			onInputWord(e) {
				this.word = e.detail.value
			},
			// 点击搜索
			onSearch() {
				this.data_list = []
				this.getDataList()
			},

			// 接口:获取数据列表
			async getDataList() {
				this.data_list = []
				let that = this
				uni.showLoading({ title: '加载中', mask: true, })
				let openkey = '513fb82e1e54251bb2c0bf95786d136a'
				let m = 'openApiGoodsRequisition'
				let a = 'getGoodsList'
				let key = this.word
				let res = await this.$getGoodsList({ openkey, m, a, key })
				if (res.code == 200) {
					this.data_list = res.data.rows
				} else {
					uni.showToast({ icon: 'none', title: res.msg })
				}
			},
		}
	}
</script>

<style scoped>
	#content {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}

	.search_div {
		position: fixed;
		height: 100rpx;
		width: calc(100%);
		background-color: white;
		z-index: 1;
	}

	.search_border {
		display: flex;
		align-items: center;
		width: calc(100% - 24rpx);
		height: calc(100% - 24rpx);
		margin: 12rpx 12rpx 12rpx 12rpx;
		border: solid 1rpx #ccc;
		border-radius: 888rpx;
	}

	.et_word {
		flex-grow: 1;
		padding: 0 0 0 48rpx;
	}

	.data_item {
		display: flex;
		flex-direction: column;
		margin: 20rpx;
		font-size: 28rpx;
	}
</style>